﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApp2.Tools;
using WindowsFormsApp2.Util;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            axEloamView1.InitDev();


            for (int i = 0; i < axEloamView1.GetResolutionNumber(0); i++)
            {
                cbb_fbl.Items.Add(axEloamView1.GetResolution(0, i));
            }
            if (cbb_fbl.Items.Count != 0)
                cbb_fbl.SelectedIndex = 0;
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            axEloamView1.Deskew(1, true);

            axEloamView1.SetResolution(0, 0);
            axEloamView1.OpenVideo(0);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            axEloamView1.DeInitDev();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            var app_path = AppUtil.GetAppDir()+@"temp\";
            var new_filename = app_path + Guid.NewGuid().ToString() + ".jpg";

            //string base64_img = axEloamView1.GetBase64(0, 2, 1);

            //axEloamView1.SaveFileByBase64(base64_img, app_path + );
           
            axEloamView1.Scan(0, new_filename, 0);

            RequestTools requestTools = new RequestTools();

            var ret = requestTools.SendRequest(new_filename);

            JObject json_boj = JObject.Parse(ret);
                       

            if (json_boj["code"].ToString() == "1")
            {
                new ResultForm
                {
                    msg = ret,
                    WindowState=FormWindowState.Maximized,
                    file_img=new_filename

                }.Show();
            }
            else
            {
                MessageBox.Show(json_boj["msg"].ToString());
            }

        }

        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            new PdfForm
            {
                WindowState = FormWindowState.Maximized
            }.ShowDialog();
        }
    }
}
